﻿using System.Collections.Generic;
using System.IO;
using System.Text;

namespace crc32
{
    public static class SfvParser
    {
        public static List<CrcData> Parse(Stream stream)
        {
            TextReader textReader = new StreamReader(stream, Encoding.ASCII);
            var line = textReader.ReadLine();
            var results = new List<CrcData>();
            while (line != null)
            {
                if (line == string.Empty || line.StartsWith(";"))
                {
                    line = textReader.ReadLine();
                    continue;
                }
                var spaceIndex = line.LastIndexOf(' ');
                var crc = line.Substring(spaceIndex + 1);
                var fileName = line.Substring(0, spaceIndex);
                results.Add(new CrcData { FileName = fileName, Crc = crc });
                line = textReader.ReadLine();
            }
            
            return results;
        }
    }
}